<%@ page import="com.afc.struts.test.persons.PersonsForm"%>
<%@ page
	import="com.afc.struts.test.persons.PersonsForm.DefaultPersonsForm"%>
<%@ page import="com.afc.struts.test.model.Person"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="com.afc.struts.utils.DateUtils"%>

<%
  String error = (String) request.getAttribute("error");
			PersonsForm form = (PersonsForm) request.getAttribute("form");
			if (form == null) {
				form = new DefaultPersonsForm();
			}
%>

<html>
<head>
<script type="text/javascript">
	function submitForm(anActionUrl, aFormElement) {
		aFormElement.action = anActionUrl;
		aFormElement.submit();
	}
</script>
</head>

<body>
	<div style="height: 50px;">
		<a href="welcome.jsp">Retour vers la page d'accueil</a>
	</div>

	<form method="post">
		Persons :
		<table  border=1 style="border-collapse:collapse;text-align: center;">
			<tr>
				<th style="padding: 5px;">Id</th>
				<th style="padding: 5px;">FirstName</th>
				<th style="padding: 5px;">LastName</th>
				<th style="padding: 5px;">Size</th>
				<th style="padding: 5px;">Birthday</th>
				<th style="padding: 5px;">Best Friend</th>
			</tr>
			<%
			  Iterator iterator = form.getPersons().iterator();
			  for (int i = 0; iterator.hasNext(); i++)
			  {
			    Person person = (Person)iterator.next();
			%>
			<tr>
				<td><input type="radio" attribute-type="int"
					name="selectedPersonId" value="<%=person.getId()%>"
					<%=form.getSelectedPersonId() == person.getId() ? "checked" : ""%>><%=person.getId()%></input>
				</td>
				<td><%=person.getFirstName()%></td>
				<td><%=person.getLastName()%></td>
				<td><%=person.getSize() != null ? person.getSize() : ""%></td>
				<td><%=person.getBirthday() != null ? DateUtils.format(person.getBirthday()) : ""%>
				</td>
				<td><%=person.getBestFriend() != null ? person.getBestFriend() : ""%>
				</td>
			</tr>
			<%
			  }
			%>
		</table>
		<br /> <input type="button" value="Add"
			onclick='submitForm("persons.add.do", this.form)' /> <input
			type="button" value="Update"
			onclick='submitForm("persons.update.do", this.form)' /> <input
			type="button" value="Remove"
			onclick='submitForm("persons.remove.do", this.form)' /> <label><%=error != null ? error : ""%></label>
	</form>

</body>

</html>